<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Javascript简介</title>
        <style></style>
    </head>
    <body>
        <form action="" method="post" onsubmit="return check()">
           用户名： <input type="text" name="username" id="username">
            密码：<input type="password" name="password" id="password">
            电话：<input type="text" name="phone"  id="phone">
            <input type="submit" value="提交">
        </form>
        <script type="text/javascript">
        function check(){
            var username = document.getElementById("username").value;
            //alert(username);
            var password = document.getElementById("password").value;
            var phone = document.getElementById("phone").value;
            if(username==null||username==""){
                alert("用户名不能为空");
                return false;
            }
            if(password==null||password==""){
                alert("密码不能为空");
                return false;
            }
            if(phone==null||phone==""){
                alert("电话不能为空");
                return false;
            }
            var patt=/^1[3456789]\d{9}$/;
            if(!patt.test(phone)){
                alert("手机格式不对");
                return  false;
            }
            return true;

        }
        </script>
    </body>
</html>